#coding=utf-8
from django.contrib.admin import widgets
from django import forms
from django.forms.models import inlineformset_factory
from DjangoBbs.BbsSetting.models import BbsThemeType
from PublicTool.CzqWidget import SelectBootstrap

import models
__author__ = 'czq'
class bbsReplyForm(forms.ModelForm):
    class Meta:
        model=models.BbsReply
        fields=("content",)
        widgets={
            'content':forms.Textarea(attrs={'class':'form-control','placeholder':u'回复内容'}),
        }

class BbsThemeForm(forms.ModelForm):
    def __init__(self,*args,**kwargs):

        has_class=kwargs.has_key('classId')
        if has_class:
            classId = kwargs['classId']
            kwargs.pop('classId')
        super(BbsThemeForm,self).__init__(*args,**kwargs)
        if has_class:
            self.fields['themeType'].queryset = BbsThemeType.objects.filter(classId=classId)

    class Meta:
        model=models.BbsTheme
        fields=('themeType','title','content','visitPerm',)
        widgets = {
            'title':forms.TextInput(attrs={'class':'form-control','placeholder':u'标题'}),
            'content':forms.Textarea(attrs={'class':'form-control','placeholder':u'内容'}),
            'themeType': SelectBootstrap,
            'visitPerm': SelectBootstrap,
        }
import models_vote
class BbsThemeVoteForm(forms.ModelForm):
    class Meta:
        model=models_vote.BbsThemeVote
        fields=('content','rank',)

class BbsThemeVoteAttrForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(BbsThemeVoteAttrForm, self).__init__(*args, **kwargs)
        self.fields['startTime'].widget = widgets.AdminSplitDateTime()
        self.fields['endTime'].widget = widgets.AdminSplitDateTime()
        #widgets.Admin
    class Meta:
        model=models_vote.BbsThemeVoteAttr
        fields=('startTime','endTime',)

#BbsThemeVoteFormSet = inlineformset_factory(models.BbsTheme, models_vote.BbsThemeVote,form=BbsThemeVoteForm,extra=5)
BbsThemeVoteAttrFormSet = inlineformset_factory(models.BbsTheme, models_vote.BbsThemeVoteAttr,form=BbsThemeVoteAttrForm,extra=1)


class BbsClassSelectForm(forms.Form):
    bbsClass=forms.ModelChoiceField(models.BbsClass.objects_search.all(),label=u'',widget=SelectBootstrap)